from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-28 14:12:55.489651
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 28, Sep, 2021
Time: 14:13:04
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.4129
Nobs: 428.000 HQIC: -46.9294
Log likelihood: 4739.28 FPE: 2.96793e-21
AIC: -47.2665 Det(Omega_mle): 2.41091e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.422216 0.091453 4.617 0.000
L1.Burgenland 0.106878 0.047400 2.255 0.024
L1.Kärnten -0.114205 0.023773 -4.804 0.000
L1.Niederösterreich 0.162608 0.101561 1.601 0.109
L1.Oberösterreich 0.112170 0.099682 1.125 0.260
L1.Salzburg 0.284156 0.049895 5.695 0.000
L1.Steiermark 0.029714 0.066492 0.447 0.655
L1.Tirol 0.107562 0.052407 2.052 0.040
L1.Vorarlberg -0.102998 0.047003 -2.191 0.028
L1.Wien -0.002154 0.091002 -0.024 0.981
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.014779 0.209392 0.071 0.944
L1.Burgenland -0.051919 0.108527 -0.478 0.632
L1.Kärnten 0.037501 0.054431 0.689 0.491
L1.Niederösterreich -0.213159 0.232535 -0.917 0.359
L1.Oberösterreich 0.494027 0.228232 2.165 0.030
L1.Salzburg 0.306814 0.114240 2.686 0.007
L1.Steiermark 0.106873 0.152240 0.702 0.483
L1.Tirol 0.312037 0.119992 2.600 0.009
L1.Vorarlberg 0.000595 0.107618 0.006 0.996
L1.Wien 0.004404 0.208360 0.021 0.983
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.241068 0.046311 5.205 0.000
L1.Burgenland 0.093135 0.024003 3.880 0.000
L1.Kärnten -0.002059 0.012038 -0.171 0.864
L1.Niederösterreich 0.211596 0.051429 4.114 0.000
L1.Oberösterreich 0.157501 0.050478 3.120 0.002
L1.Salzburg 0.034638 0.025266 1.371 0.170
L1.Steiermark 0.022421 0.033671 0.666 0.505
L1.Tirol 0.069192 0.026539 2.607 0.009
L1.Vorarlberg 0.059471 0.023802 2.499 0.012
L1.Wien 0.114389 0.046083 2.482 0.013
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186227 0.045392 4.103 0.000
L1.Burgenland 0.046809 0.023526 1.990 0.047
L1.Kärnten -0.006628 0.011799 -0.562 0.574
L1.Niederösterreich 0.140054 0.050409 2.778 0.005
L1.Oberösterreich 0.318249 0.049476 6.432 0.000
L1.Salzburg 0.100220 0.024765 4.047 0.000
L1.Steiermark 0.129306 0.033003 3.918 0.000
L1.Tirol 0.077620 0.026012 2.984 0.003
L1.Vorarlberg 0.055858 0.023329 2.394 0.017
L1.Wien -0.047738 0.045168 -1.057 0.291
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.205432 0.089984 2.283 0.022
L1.Burgenland -0.046806 0.046639 -1.004 0.316
L1.Kärnten -0.033671 0.023391 -1.439 0.150
L1.Niederösterreich 0.109600 0.099930 1.097 0.273
L1.Oberösterreich 0.169591 0.098081 1.729 0.084
L1.Salzburg 0.250934 0.049093 5.111 0.000
L1.Steiermark 0.078419 0.065424 1.199 0.231
L1.Tirol 0.124662 0.051566 2.418 0.016
L1.Vorarlberg 0.115852 0.046248 2.505 0.012
L1.Wien 0.029964 0.089541 0.335 0.738
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.034348 0.069356 0.495 0.620
L1.Burgenland 0.022518 0.035947 0.626 0.531
L1.Kärnten 0.054403 0.018029 3.018 0.003
L1.Niederösterreich 0.208821 0.077022 2.711 0.007
L1.Oberösterreich 0.342201 0.075596 4.527 0.000
L1.Salzburg 0.045500 0.037839 1.202 0.229
L1.Steiermark -0.010488 0.050426 -0.208 0.835
L1.Tirol 0.112179 0.039745 2.823 0.005
L1.Vorarlberg 0.069074 0.035646 1.938 0.053
L1.Wien 0.122461 0.069014 1.774 0.076
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.194953 0.084940 2.295 0.022
L1.Burgenland 0.015941 0.044024 0.362 0.717
L1.Kärnten -0.057357 0.022080 -2.598 0.009
L1.Niederösterreich -0.116960 0.094328 -1.240 0.215
L1.Oberösterreich 0.193125 0.092583 2.086 0.037
L1.Salzburg 0.033023 0.046342 0.713 0.476
L1.Steiermark 0.285685 0.061757 4.626 0.000
L1.Tirol 0.491200 0.048675 10.091 0.000
L1.Vorarlberg 0.076369 0.043655 1.749 0.080
L1.Wien -0.113209 0.084522 -1.339 0.180
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158647 0.092818 1.709 0.087
L1.Burgenland -0.012182 0.048108 -0.253 0.800
L1.Kärnten 0.063680 0.024128 2.639 0.008
L1.Niederösterreich 0.193605 0.103077 1.878 0.060
L1.Oberösterreich -0.125378 0.101170 -1.239 0.215
L1.Salzburg 0.234504 0.050640 4.631 0.000
L1.Steiermark 0.151817 0.067485 2.250 0.024
L1.Tirol 0.049070 0.053190 0.923 0.356
L1.Vorarlberg 0.130578 0.047704 2.737 0.006
L1.Wien 0.157951 0.092361 1.710 0.087
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.479520 0.050415 9.511 0.000
L1.Burgenland -0.005911 0.026130 -0.226 0.821
L1.Kärnten -0.009644 0.013105 -0.736 0.462
L1.Niederösterreich 0.205080 0.055987 3.663 0.000
L1.Oberösterreich 0.252895 0.054951 4.602 0.000
L1.Salzburg 0.023235 0.027505 0.845 0.398
L1.Steiermark -0.021986 0.036655 -0.600 0.549
L1.Tirol 0.067066 0.028891 2.321 0.020
L1.Vorarlberg 0.060508 0.025911 2.335 0.020
L1.Wien -0.048301 0.050167 -0.963 0.336
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.021427 0.078403 0.139906 0.131085 0.041656 0.073514 0.001054 0.185537
Kärnten 0.021427 1.000000 -0.045018 0.129210 0.048286 0.072071 0.453896 -0.090454 0.090011
Niederösterreich 0.078403 -0.045018 1.000000 0.281931 0.080475 0.265664 0.019448 0.135924 0.260550
Oberösterreich 0.139906 0.129210 0.281931 1.000000 0.176556 0.288886 0.156633 0.101913 0.136652
Salzburg 0.131085 0.048286 0.080475 0.176556 1.000000 0.126034 0.055993 0.107435 0.051036
Steiermark 0.041656 0.072071 0.265664 0.288886 0.126034 1.000000 0.130884 0.094078 -0.016886
Tirol 0.073514 0.453896 0.019448 0.156633 0.055993 0.130884 1.000000 0.046489 0.118027
Vorarlberg 0.001054 -0.090454 0.135924 0.101913 0.107435 0.094078 0.046489 1.000000 -0.046566
Wien 0.185537 0.090011 0.260550 0.136652 0.051036 -0.016886 0.118027 -0.046566 1.000000